#include "Common.h"
#include "Depot.h"

using namespace RayFrame;

IMPL_SINGLETON(Depot);

Depot::Depot()
{

}

Depot::~Depot()
{
  for(MapDepotIter iter = m_depot.begin();
    iter != m_depot.end();
    iter++)
  {
    delete iter->second;
  }
  m_depot.clear();
}

void Depot::AddDepotBucket(Bucket *bucket)
{
  STRING bucketName = bucket->GetName();
  if( m_depot.find(bucketName)!= m_depot.end() )
    throw new MyException("Bucket already exists!");

  m_depot.insert( std::make_pair(bucketName, bucket) );
}

void Depot::RemoveDepotBucket(Bucket* bucket)
{
  MapDepotIter iter = m_depot.find(bucket->GetName());
  if( iter != m_depot.end() )
  {
    delete iter->second;
    m_depot.erase(iter);
  }
}